import { MemoryDatabase, PostgresDatabase } from "@supersavely/db";

export type DatabaseProvider = MemoryDatabase | PostgresDatabase;
let databaseInstance: DatabaseProvider;

if (process.env.NODE_ENV === "test") {
  databaseInstance = new MemoryDatabase();
} else {
  databaseInstance = new PostgresDatabase(process.env.DATABASE_URL!);
}

export const db = databaseInstance.database;

export type DB = typeof db;

export default databaseInstance;
